'''
字典
定义:
被定义在{ }中数据，以key-value键值对，
字典没有下表，取值靠 键

'''
#定义
# 定义
data_01 = {}
data_02 = { "nginx":"1.18","docker":"25.4","tomcat":"9.5"}
print(type(data_01),type(data_02))
data_03 = { "10.1.1.1":["root","redhat", 22],"10.1.1.2":["admin","123",44444]}
print(type(data_03))

# 添加数据 (键不存在)
data_02 = { "nginx":"1.18","docker":"25.4","tomcat":"9.5"}
data_02["redis"] = "5.6"
print(data_02)

# 修改数据 (键已存在)
data_02["nginx"]= ("1.20")
print (data_02)

# 获取数据,key
# 报错会显示键错误
docker_version = data_02["docker"]
print (docker_version)

# 获取数据，字典.get(key)
# 不会报错，取不着值会返回空值 none ,更推荐这个方法
redis_version = data_02.get("redis")
print( redis_version)

#字典.keys()，以列表的形式返回字典中所有的键
data_02 = { "nginx":"1.18","docker":"25.4","tomcat":"9.5"}
software =data_02.keys()
print("software= %s" %software)



new_01 = input("软件名称：").strip()
if new_01 in software:
    print("软件名称：%s ,版本：%s" %(new_01 , data_02.get(new_01)))
else:
    print("软件【%s】不存在！！" %new_01)

# 遍历字典 "items()方法" [("a","b"),("a","b"),("a","b")]列表套元组
# data_03 = { "nginx":"1.18","docker":"25.4"}
# for k,v in data_02.items():
# print ("软件名称:%s，版本:%s" %(k,v) )





